﻿using Microsoft.AspNetCore.Mvc;
using WCS_Entity.Dto;
using WCS_Service.Interface;
using WCS_Service.Services;

namespace WCS.Controllers
{
    /// <summary>
    /// Rcs服务启动暂停管理接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class RcsServiceOperateController : ControllerBase
    {
        private readonly IRcsOperateService _rcsOperateService;

        public RcsServiceOperateController(IRcsOperateService rcsOperateService)
        {
            _rcsOperateService = rcsOperateService;
        }

        #region 自动化设备服务管理
        /// <summary>
        /// 启动指定自动化设备
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> StartRcsAsync([FromBody]int id)
        {
            var result = new WebApiCallBack();
            result.status = await _rcsOperateService.CreatRcsServiceAsync(id);
            result.msg = result.status ? "自动化设备服务启动成功" : "自动化设备服务启动失败";
            return result;
        }
        /// <summary>
        /// 启动批量自动化设备
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> StartBatchRcsServiceAsync([FromBody] List<int> ids)
        {
            var result = new WebApiCallBack();
            result.status = await _rcsOperateService.CreatBatchRcsServiceAsync(ids);
            result.msg = result.status ? "批量自动化设备服务启动成功" : "批量自动化设备服务启动失败";
            return result;
        }
        /// <summary>
        /// 停止启动的自动化设备服务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> StopRcsAsync([FromBody] int id)
        {
            var result = new WebApiCallBack();
            result.status = await _rcsOperateService.StopRcsServiceAsync(id);
            result.msg = result.status ? "自动化服务停止成功" : "自动化服务停止失败";
            return result;
        }
        /// <summary>
        /// 停止批量自动化设备服务
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> StopBatchRcsServiceAsync([FromBody] List<int> ids)
        {
            var result = new WebApiCallBack();
            result.status = await _rcsOperateService.StopBatchRcsServiceAsync(ids);
            result.msg = result.status ? "批量自动化服务停止成功" : "批量自动化服务停止失败";
            return result;
        }
        #endregion
    }
}
